package com.lm.scau.dyb.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lm.scau.dyb.R;
import com.lm.scau.dyb.activity.base.BaseActivity;
import com.lm.scau.dyb.activity.base.NoticeActivity;
import com.lm.scau.dyb.adapter.NoticeAdapter;
import com.lm.scau.dyb.bean.Notice;
import com.lm.scau.dyb.db.Dalx.NoticeDalx;

import java.util.ArrayList;
import java.util.List;

/**
 * Function:
 * auth：liming on 2016/8/5 11:03
 * mail：liming@wxchina.com
 */
public class NoticeFragment extends Fragment {
    private ListView noticeList;
    private NoticeAdapter adapter;
    private List<Notice> notices;
    private BaseActivity activity;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = (BaseActivity) getActivity();
        if (null == notices) {
            NoticeDalx dalx = new NoticeDalx(activity);
            notices = dalx.getNotices();
            adapter = new NoticeAdapter(notices, activity);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_notice, container, false);
        noticeList = (ListView) view.findViewById(R.id.notice_list_view);
        noticeList.setAdapter(adapter);
        initAction();
        return view;
    }

    private void initAction() {
        noticeList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String noticeInfo = notices.get(position).getNoticeInfo();
                String noticeTime = notices.get(position).getNoticeTime();
                String noticeTitle = notices.get(position).getNoticeTitle();
                Bundle bundle = new Bundle();
                bundle.putString("noticeInfo", noticeInfo);
                bundle.putString("noticeTime", noticeTime);
                bundle.putString("noticeTitle", noticeTitle);
                activity.startActivity(NoticeActivity.class, bundle);
            }
        });
    }
}
